package org.pearl.springbootsecurity.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.pearl.springbootsecurity.demo.dao.UserMapper;
import org.pearl.springbootsecurity.demo.entity.Permission;
import org.pearl.springbootsecurity.demo.pojo.UserInfoDO;
import org.pearl.springbootsecurity.demo.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author td
 * @since 2021-07-02
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    PermissionService permissionService;
    @Autowired
    UserMapper userMapper;

    @GetMapping("/test")
    public List<Permission> test(){
        // 更新
        Permission permission=new Permission();
        permission.setPermissionId(21);
        permission.setCode("rddd");
        LambdaUpdateWrapper<Permission> lambdaUpdateWrapper=new LambdaUpdateWrapper<>();
        boolean b = permissionService.updateById(permission);

        // 单表查询
        LambdaQueryWrapper<Permission> permissionLambdaQueryWrapper = new LambdaQueryWrapper<>();
        permissionLambdaQueryWrapper.select(Permission::getCode,Permission::getTenantId);
        List<Permission> list = permissionService.list(permissionLambdaQueryWrapper);
        // 多表查询
        UserInfoDO test = userMapper.getUserInfoByUserName("test");
        return list;
    }

}

